package com.cmc.cloud.cmclink.doc.api.document;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.api.document.req.si.*;
import com.cmc.cloud.cmclink.doc.service.si.BlnoService;
import com.cmc.cloud.cmclink.doc.vo.blnovo.operatevo.BlnoOperateReqVO;
import com.cmes.framework.common.pojo.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;


/**
 * SI信息创建
* @author stq
* @date 2025/9/15
*/
@Slf4j
@RestController
@Valid
public class BlnoInfoUpdateApiImpl implements BlnoInfoUpdateApi {

   @Resource
   private BlnoService blnoService;

   /**
    * 修改SIGN TYPE
    * @param updateDto
    * @return
    */
    @Override
    public CommonResult<Void> updateSignType(BlnoSignTypeUpdateDto updateDto) {
        blnoService.updateSignType(updateDto);
        return CommonResult.success();
    }

    /**
     * 取消签发
     * @param blnoId
     * @return
     */
    @Override
    public CommonResult<Void> cancelSignType(Long blnoId) {
        BlnoOperateReqVO param = new BlnoOperateReqVO();
        param.setBlnoIds(Collections.singletonList(blnoId));
        blnoService.cancelTelex(param);
        return CommonResult.success();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<Void> batchUpdateSignType(@Valid @RequestBody List<BlnoSignTypeUpdateDto> updateDtoList) {
        updateDtoList.forEach(updateDto -> blnoService.updateSignType(updateDto));
        return CommonResult.success();
    }
}
